package com.ebelter.seneo.ui.activitys;


import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.ebelter.btcomlib.bases.activity.BaseActivity;
import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.seneo.R;

public class WebActivity extends SeneoBaseActivity {


    public static final String WEB_URL="1";
    public static final String WEB_TITLE="2";


    ImageView top_iv;
    TextView top_tv1;

    public static void openWebActivity(Context context,String web_url,String title){
        Intent intent=new Intent(context,WebActivity.class);
        intent.putExtra(WEB_URL,web_url);
        intent.putExtra(WEB_TITLE,title);
        context.startActivity(intent);
    }



    WebView web;
    String url;
    String title;
    @Override
    protected int loadLayoutById() {
        return R.layout.activity_web;
    }

    @Override
    protected void initData() {



        url=getIntent().getStringExtra(WEB_URL);
        title=getIntent().getStringExtra(WEB_TITLE);

        top_iv = findViewById(R.id.top_iv);
        top_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (web!=null){
                    if (web.canGoBack()){
                        web.goBack();
                        return;
                    }
                }
                finish();
            }
        });

        top_tv1 = findViewById(R.id.top_tv1);
        top_tv1.setText(title);
        ViewUtils.displayView(top_tv1);

        web = findViewById(R.id.web);
        web.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

        });
        web.loadUrl(url);
    }

    @Override
    public boolean
    onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && web.canGoBack()) {
            web.goBack();//返回上个页面
            return true;
        }
        return super.onKeyDown(keyCode, event);//退出H5界面

    }
}
